<template>
	<view class="cate">
		<view class="cateLeft">
			<view :class="{active:index==activeKey,menu:true}" v-for="(item,index) in menuList" :key="item._id" @click="menuClick(item,index)">
				{{item.typeOne}}
			</view>
		</view>
		<view class="category-list">
			<view class="category" v-for="(row, index) in cateList" :key="index" @click="gotoSearch(row.typeTwo)">
				<view class="img"><image :src="row.Img"></image></view>
				<view class="text">{{ row.typeTwo }}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import catesApi from "../../api/cate";
	export default {
		data() {
			return {
				activeKey:0,
				menuList:[],
				cateList:[],
				query:"",
			}
		},
		methods: {
			menuClick(item,index=0){
				this.activeKey = index;
				this.query = item.typeOne;
				catesApi.getTwoCate({
					_id:item._id,
					success:({data})=>{
						this.cateList = data;
					}
				})
			},
			gotoSearch(name){
				uni.navigateTo({
					url:"/pages/search/search?search="+this.query,
				})
			}
		},
		created() {
			catesApi.getOneCate({
				success:({data})=>{
					this.menuList = data;
					this.menuClick(this.menuList[0]);
				}
			})
		}
	}
</script>

<style lang="scss" scoped>
.cate{
	display: flex;
	align-items: flex-start;
}
.cateLeft{
	border-right: 1px solid #eee;
}
.menu{
	margin: 40rpx 0;
	width: 150rpx;
	height: 40rpx;
	display: flex;
	justify-content: center;
	align-items: center;
	font-size: 32rpx;
	color: #aaa;
	border-left: 3px solid transparent;
}
.active{
	font-size: 40rpx;
	color:#000;
	border-left: 3px solid #f26522;
}
.category-list {
	width: 92%;
	margin: 0 4%;
	padding: 0 0 30rpx 0;
	border-bottom: solid 2rpx #78cdd1;
	display: flex;
	align-items: flex-start;
	flex-wrap: wrap;
	.category {
		width: 25%;
		height: 100rpx;
		margin-top: 50rpx;
		display: flex;
		flex-wrap: wrap;
		.img {
			width: 100%;
			display: flex;
			justify-content: center;
			image {
				width: 50rpx;
				height: 50rpx;
			}
		}
		.text {
			margin-top: 5rpx;
			width: 100%;
			display: flex;
			justify-content: center;
			font-size: 24rpx;
			color: #3c3c3c;
		}
	}
}
</style>
